package com.wangzefeng.shop.security.encoder;

import com.alibaba.nacos.common.utils.MD5Utils;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Auther: wangzefeng
 * @Date: 2021/3/19 09:57
 * @Description:
 */
public class MD5PasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence charSequence) {
        return MD5Utils.md5Hex((String) charSequence,"UTF-8");
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        String md5Hex = MD5Utils.md5Hex((String) charSequence, "UTF-8");
        return md5Hex.equals(s);
    }

    public static void main(String[] args) {
        MD5PasswordEncoder md5PasswordEncoder=new MD5PasswordEncoder();
        String abcdef = md5PasswordEncoder.encode("123456");
        System.out.println(abcdef);
        System.out.println(md5PasswordEncoder.matches("12345",abcdef));
    }
}
